#include <algorithm>
#include <cstdint>
#include <iostream>
#include <istream>
#include <ostream>
#include <vector>
using ll = int64_t;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n,k;
    std::cin>>n>>k;
    std::vector<ll> v(n+1),dp(n+1);
    for(ll i=1;i<=n;i++){
        std::cin>>v[i];
    }
    for(ll i=1;i<=n;i++){
        ll max=0;
        for(ll len=1;len<=k&&len<=i;len++){
            max=std::max(max,v[i-len+1]);
            dp[i]=std::max(dp[i],max*len+dp[i-len]);
        }
    }
    std::cout<<dp[n]<<std::endl;
    _Exit(0);
}